// pages/carMotoType/carMotoType.js
var a = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
      car:'',
      xiugai:'',
        id: '',
        ppid:'',
        name: '',
        cxList: [], //车型List
        ppname:'',
        series:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(g) {
        console.log('ggg',g)
        this.setData({
            id: g.id,
            series: g.name,
            ppname:g.ppname,
            ppid:g.ppid,
            xiugai:g.xiugai,
            car :g.car
        })
        var t = wx.getSystemInfoSync(),
            e = this;
        a.util.request({
            url: "entry/wxapp/Api",
            data: {
                m: "monai_market",
                r: "sale.index.carMotoType",
                vehicel_id: e.data.id
            },
            cachetime: "0",
            success: function(c) {
              console.log(c)
                if (c.data.data[0].length == 0 && e.data.xiugai == 2) {
                    console.log(e.data.id)
                    a.globalData.id = e.data.id
                    a.globalData.name = e.data.series
                    a.globalData.ppname = e.data.ppname
                    a.globalData.ppid = e.data.ppid
                    a.globalData.series = e.data.series
                    wx.switchTab({
                        url: '../sale/index'
                    })
                } else if (c.data.data[0].length == 0 && e.data.xiugai != 2){
                  console.log('shnagdd')
                  var pages = getCurrentPages();
                  var currPage = pages[pages.length - 1];   //当前页面
                  var prevPage = pages[pages.length - 4];  //上一个页面
                  prevPage.setData({
                    id: e.data.id,
                    selectbrand: e.data.series,
                    ppname: e.data.ppname,
                    ppid: e.data.ppid,
                    car: e.data.car,
                    xiugai: e.data.xiugai,
                    series: e.data.series
                  });
                  wx.navigateBack({ delta: 3 });
                  // wx.navigateTo({
                  //   url: "/pages/saledetail/index?id=" + e.data.id + '&name=' + e.data.name + '&ppname=' + e.data.ppname + '&ppid=' + e.data.ppid + '&car=' + e.data.car + '&xiugai=' + e.data.xiugai
                  // })
                } else {
                  console.log('21213132')
                    e.setData({
                        cxList: c.data.data,
                    });
                }
            }
        });
    },
    tz:function(ss){
      var t = this
      console.log(ss)
      var id = ss.currentTarget.dataset.id
      var name = ss.currentTarget.dataset.name
      t.setData({
        id: id,
        name:name
      })
      if (t.data.xiugai == 2){
        a.globalData.id = id
        a.globalData.name = name
        a.globalData.ppname = t.data.ppname
        a.globalData.ppid = t.data.ppid
        a.globalData.series = t.data.series
        wx.switchTab({
          url: '../sale/index'
        })
      }else{
        var pages = getCurrentPages();
        var currPage = pages[pages.length - 1];   //当前页面
        var prevPage = pages[pages.length - 4];  //上一个页面
        prevPage.setData({
          id: id,
          selectbrand:name,
          ppname:t.data.ppname ,
          ppid: t.data.ppid,
          car:t.data.car,
          xiugai: t.data.xiugai,
          series: t.data.series
        });
        console.log(pages)
        console.log(currPage)
        console.log(prevPage)
        wx.navigateBack({ delta: 3});
        //prevPage?????
        // wx.navigateTo({
        //   url: "/pages/saledetail/index?id=" + id + '&name=' + name + '&ppname=' + t.data.ppname + '&ppid=' + t.data.ppid + '&car=' + t.data.car + '&xiugai=' + t.data.xiugai
        // })
      }
       
    }
})